﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>上架管理</title>
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/demo.css">
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/Styles/Manage_Order.css" rel="stylesheet" />
    <link href="~/Content/Styles/Order.css" rel="stylesheet" />
    <script>
        //没事别看这段代码
        $(function () {
            GetMer();//加载操作员管理的所有商户
            $('#btndetail').linkbutton('disable');
            $('#btnadd').linkbutton('disable');
            $('#btnedit').linkbutton('disable');
            $('#btndell').linkbutton('disable');

            $('#MaTimeB').combobox({
                valueField: 'id',
                textField: 'text',
                data: [
                    {
                        "id": "0",
                        "text": "不允许预约",
                    }, {
                        "id": "0000",
                        "text": "00:00",
                    }, {
                        "id": "0015",
                        "text": "00:15",
                    }, {
                        "id": "0030",
                        "text": "00:30"
                    }, {
                        "id": "0045",
                        "text": "00:45",
                    }, {
                        "id": "0100",
                        "text": "01:00"
                    }, {
                        "id": "0115",
                        "text": "01:15",
                    }, {
                        "id": "0130",
                        "text": "01:30"
                    }, {
                        "id": "0145",
                        "text": "01:45",
                    }, {
                        "id": "0200",
                        "text": "02:00"
                    }, {
                        "id": "0215",
                        "text": "02:15",
                    }, {
                        "id": "0230",
                        "text": "02:30"
                    }, {
                        "id": "0245",
                        "text": "02:45",
                    }, {
                        "id": "0300",
                        "text": "03:00"
                    }, {
                        "id": "0315",
                        "text": "03:15",
                    }, {
                        "id": "0330",
                        "text": "03:30"
                    }, {
                        "id": "0345",
                        "text": "03:45",
                    }, {
                        "id": "0400",
                        "text": "04:00"
                    }, {
                        "id": "0415",
                        "text": "04:15",
                    }, {
                        "id": "0430",
                        "text": "04:30"
                    }, {
                        "id": "0445",
                        "text": "04:45",
                    }, {
                        "id": "0500",
                        "text": "05:00"
                    }, {
                        "id": "0515",
                        "text": "05:15",
                    }, {
                        "id": "0530",
                        "text": "05:30"
                    }, {
                        "id": "0545",
                        "text": "05:45",
                    }, {
                        "id": "0600",
                        "text": "06:00"
                    }, {
                        "id": "0615",
                        "text": "06:15",
                    }, {
                        "id": "0630",
                        "text": "06:30"
                    }, {
                        "id": "0645",
                        "text": "06:45",
                    }, {
                        "id": "0700",
                        "text": "07:00"
                    }, {
                        "id": "0715",
                        "text": "07:15",
                    }, {
                        "id": "0730",
                        "text": "07:30"
                    }, {
                        "id": "0745",
                        "text": "07:45",
                    }, {
                        "id": "0800",
                        "text": "08:00"
                    }, {
                        "id": "0815",
                        "text": "08:15",
                    }, {
                        "id": "0830",
                        "text": "08:30"
                    }, {
                        "id": "0845",
                        "text": "08:45",
                    }, {
                        "id": "0900",
                        "text": "09:00"
                    }, {
                        "id": "0915",
                        "text": "09:15",
                    }, {
                        "id": "0930",
                        "text": "09:30"
                    }, {
                        "id": "0945",
                        "text": "09:45",
                    }, {
                        "id": "1000",
                        "text": "10:00"
                    }, {
                        "id": "1015",
                        "text": "10:15",
                    }, {
                        "id": "1030",
                        "text": "10:30"
                    }, {
                        "id": "1045",
                        "text": "10:45",
                    }, {
                        "id": "1100",
                        "text": "11:00"
                    }, {
                        "id": "1115",
                        "text": "11:15",
                    }, {
                        "id": "1130",
                        "text": "11:30"
                    }, {
                        "id": "1145",
                        "text": "11:45",
                    }, {
                        "id": "1200",
                        "text": "12:00"
                    }, {
                        "id": "1215",
                        "text": "12:15",
                    }, {
                        "id": "1230",
                        "text": "12:30"
                    }, {
                        "id": "1245",
                        "text": "12:45",
                    }, {
                        "id": "1300",
                        "text": "13:00"
                    }, {
                        "id": "1315",
                        "text": "13:15",
                    }, {
                        "id": "1330",
                        "text": "13:30"
                    }, {
                        "id": "1345",
                        "text": "13:45",
                    }, {
                        "id": "1400",
                        "text": "14:00"
                    }, {
                        "id": "1415",
                        "text": "14:15",
                    }, {
                        "id": "1430",
                        "text": "14:30"
                    }, {
                        "id": "1445",
                        "text": "14:45",
                    }, {
                        "id": "1500",
                        "text": "15:00"
                    }, {
                        "id": "1515",
                        "text": "15:15",
                    }, {
                        "id": "1530",
                        "text": "15:30"
                    }, {
                        "id": "1545",
                        "text": "15:45",
                    }, {
                        "id": "1600",
                        "text": "16:00"
                    }, {
                        "id": "1615",
                        "text": "16:15",
                    }, {
                        "id": "1630",
                        "text": "16:30"
                    }, {
                        "id": "1645",
                        "text": "16:45",
                    }, {
                        "id": "1700",
                        "text": "17:00"
                    }, {
                        "id": "1715",
                        "text": "17:15",
                    }, {
                        "id": "1730",
                        "text": "17:30"
                    }, {
                        "id": "1745",
                        "text": "17:45",
                    }, {
                        "id": "1800",
                        "text": "18:00"
                    }, {
                        "id": "1815",
                        "text": "18:15",
                    }, {
                        "id": "1830",
                        "text": "18:30"
                    }, {
                        "id": "1845",
                        "text": "18:45",
                    }, {
                        "id": "1900",
                        "text": "19:00"
                    }, {
                        "id": "1915",
                        "text": "19:15",
                    }, {
                        "id": "1930",
                        "text": "19:30"
                    }, {
                        "id": "1945",
                        "text": "19:45",
                    }, {
                        "id": "2000",
                        "text": "20:00"
                    }, {
                        "id": "2015",
                        "text": "20:15",
                    }, {
                        "id": "2030",
                        "text": "20:30"
                    }, {
                        "id": "2045",
                        "text": "20:45",
                    }, {
                        "id": "2100",
                        "text": "21:00"
                    }, {
                        "id": "2115",
                        "text": "21:15",
                    }, {
                        "id": "2130",
                        "text": "21:30"
                    }, {
                        "id": "2145",
                        "text": "21:45",
                    }, {
                        "id": "2200",
                        "text": "22:00"
                    }, {
                        "id": "2215",
                        "text": "22:15",
                    }, {
                        "id": "2230",
                        "text": "22:30"
                    }, {
                        "id": "2245",
                        "text": "22:45",
                    }, {
                        "id": "2300",
                        "text": "23:00"
                    }, {
                        "id": "2315",
                        "text": "00:00",
                    }, {
                        "id": "2330",
                        "text": "23:30"
                    }, {
                        "id": "2345",
                        "text": "23:45",
                    }, ]
            })

            $('#MaTimeE').combobox({
                valueField: 'id',
                textField: 'text',
                data: [{
                    "id": "0",
                    "text": "不允许预约",
                }, {
                    "id": "0000",
                    "text": "00:00",
                }, {
                    "id": "0015",
                    "text": "00:15",
                }, {
                    "id": "0030",
                    "text": "00:30"
                }, {
                    "id": "0045",
                    "text": "00:45",
                }, {
                    "id": "0100",
                    "text": "01:00"
                }, {
                    "id": "0115",
                    "text": "01:15",
                }, {
                    "id": "0130",
                    "text": "01:30"
                }, {
                    "id": "0145",
                    "text": "01:45",
                }, {
                    "id": "0200",
                    "text": "02:00"
                }, {
                    "id": "0215",
                    "text": "02:15",
                }, {
                    "id": "0230",
                    "text": "02:30"
                }, {
                    "id": "0245",
                    "text": "02:45",
                }, {
                    "id": "0300",
                    "text": "03:00"
                }, {
                    "id": "0315",
                    "text": "03:15",
                }, {
                    "id": "0330",
                    "text": "03:30"
                }, {
                    "id": "0345",
                    "text": "03:45",
                }, {
                    "id": "0400",
                    "text": "04:00"
                }, {
                    "id": "0415",
                    "text": "04:15",
                }, {
                    "id": "0430",
                    "text": "04:30"
                }, {
                    "id": "0445",
                    "text": "04:45",
                }, {
                    "id": "0500",
                    "text": "05:00"
                }, {
                    "id": "0515",
                    "text": "05:15",
                }, {
                    "id": "0530",
                    "text": "05:30"
                }, {
                    "id": "0545",
                    "text": "05:45",
                }, {
                    "id": "0600",
                    "text": "06:00"
                }, {
                    "id": "0615",
                    "text": "06:15",
                }, {
                    "id": "0630",
                    "text": "06:30"
                }, {
                    "id": "0645",
                    "text": "06:45",
                }, {
                    "id": "0700",
                    "text": "07:00"
                }, {
                    "id": "0715",
                    "text": "07:15",
                }, {
                    "id": "0730",
                    "text": "07:30"
                }, {
                    "id": "0745",
                    "text": "07:45",
                }, {
                    "id": "0800",
                    "text": "08:00"
                }, {
                    "id": "0815",
                    "text": "08:15",
                }, {
                    "id": "0830",
                    "text": "08:30"
                }, {
                    "id": "0845",
                    "text": "08:45",
                }, {
                    "id": "0900",
                    "text": "09:00"
                }, {
                    "id": "0915",
                    "text": "09:15",
                }, {
                    "id": "0930",
                    "text": "09:30"
                }, {
                    "id": "0945",
                    "text": "09:45",
                }, {
                    "id": "1000",
                    "text": "10:00"
                }, {
                    "id": "1015",
                    "text": "10:15",
                }, {
                    "id": "1030",
                    "text": "10:30"
                }, {
                    "id": "1045",
                    "text": "10:45",
                }, {
                    "id": "1100",
                    "text": "11:00"
                }, {
                    "id": "1115",
                    "text": "11:15",
                }, {
                    "id": "1130",
                    "text": "11:30"
                }, {
                    "id": "1145",
                    "text": "11:45",
                }, {
                    "id": "1200",
                    "text": "12:00"
                }, {
                    "id": "1215",
                    "text": "12:15",
                }, {
                    "id": "1230",
                    "text": "12:30"
                }, {
                    "id": "1245",
                    "text": "12:45",
                }, {
                    "id": "1300",
                    "text": "13:00"
                }, {
                    "id": "1315",
                    "text": "13:15",
                }, {
                    "id": "1330",
                    "text": "13:30"
                }, {
                    "id": "1345",
                    "text": "13:45",
                }, {
                    "id": "1400",
                    "text": "14:00"
                }, {
                    "id": "1415",
                    "text": "14:15",
                }, {
                    "id": "1430",
                    "text": "14:30"
                }, {
                    "id": "1445",
                    "text": "14:45",
                }, {
                    "id": "1500",
                    "text": "15:00"
                }, {
                    "id": "1515",
                    "text": "15:15",
                }, {
                    "id": "1530",
                    "text": "15:30"
                }, {
                    "id": "1545",
                    "text": "15:45",
                }, {
                    "id": "1600",
                    "text": "16:00"
                }, {
                    "id": "1615",
                    "text": "16:15",
                }, {
                    "id": "1630",
                    "text": "16:30"
                }, {
                    "id": "1645",
                    "text": "16:45",
                }, {
                    "id": "1700",
                    "text": "17:00"
                }, {
                    "id": "1715",
                    "text": "17:15",
                }, {
                    "id": "1730",
                    "text": "17:30"
                }, {
                    "id": "1745",
                    "text": "17:45",
                }, {
                    "id": "1800",
                    "text": "18:00"
                }, {
                    "id": "1815",
                    "text": "18:15",
                }, {
                    "id": "1830",
                    "text": "18:30"
                }, {
                    "id": "1845",
                    "text": "18:45",
                }, {
                    "id": "1900",
                    "text": "19:00"
                }, {
                    "id": "1915",
                    "text": "19:15",
                }, {
                    "id": "1930",
                    "text": "19:30"
                }, {
                    "id": "1945",
                    "text": "19:45",
                }, {
                    "id": "2000",
                    "text": "20:00"
                }, {
                    "id": "2015",
                    "text": "20:15",
                }, {
                    "id": "2030",
                    "text": "20:30"
                }, {
                    "id": "2045",
                    "text": "20:45",
                }, {
                    "id": "2100",
                    "text": "21:00"
                }, {
                    "id": "2115",
                    "text": "21:15",
                }, {
                    "id": "2130",
                    "text": "21:30"
                }, {
                    "id": "2145",
                    "text": "21:45",
                }, {
                    "id": "2200",
                    "text": "22:00"
                }, {
                    "id": "2215",
                    "text": "22:15",
                }, {
                    "id": "2230",
                    "text": "22:30"
                }, {
                    "id": "2245",
                    "text": "22:45",
                }, {
                    "id": "2300",
                    "text": "23:00"
                }, {
                    "id": "2315",
                    "text": "00:00",
                }, {
                    "id": "2330",
                    "text": "23:30"
                }, {
                    "id": "2345",
                    "text": "23:45",
                }, ]
            })
        })
        //没事别看这段代码
        var Mer;
        var diplayText;//商户名称
        var SheID;
        //获取商户
        function GetMer() {
            var grid = $('#SearchMer').combogrid({
                panelWidth: 500,
                idField: 'MerID',
                textField: 'MerName',
                url: '/Order_Shelves/getMer',
                method: 'post',
                pageSize: 100,
                pageList: [100],
                pagination: true,
                rownumbers: true,
                fitColumns: true,
                columns: [[
                    { field: 'MerID', title: '商户ID', width: 80, align: 'center' },
                    { field: 'MerName', title: '商户名称', width: 80, align: 'center' },
                    { field: 'MerTxt', title: '商户介绍', width: 120, align: 'center' },
                    { field: 'MerAdr', title: '商户地址', width: 80, align: 'center' },
                    { field: 'MerCall', title: '商户联系电话', width: 80, align: 'center' }
                ]],
                onSelect: function (index, row) {
                    diplayText = row[grid.combogrid('options').textField];
                    Mer = $('#SearchMer').combogrid("getValue");//获取操作员
                    //加载对应的商品
                    initTable(Mer);
                    //加载对应的商品分类
                    GetOrderType(Mer);
                    //控制增删查改的权限
                    $.post("/Order_Shelves/getPower", function (database) {
                        if (database != "") {
                            $('#btndetail').linkbutton('enable');
                            if (database.Add == 1) {
                                $('#btnadd').linkbutton('enable');
                            }
                            if (database.Dell == 1) {
                                $('#btndell').linkbutton('enable');
                            }
                            if (database.Edit == 1) {
                                $('#btnedit').linkbutton('enable');
                            }
                        }
                    })
                },
                onLoadSuccess: function () {
                    //分页后判断下是否有选中的数据行，combogrid会依据上一次选中的值进行初始化，选中datagrid数据行和设置显示值
                    if (!grid.combogrid('grid').datagrid('getSelected'))//不在当前页
                    {
                        $('#SearchMer').combogrid("setValue", diplayText);
                    }
                }
            });
        }

        //获取商品分类
        function GetOrderType() {
            $.get("/Order_Shelves/getOrderType?MerID=" + Mer, {}, function (database) {
                var a = {
                    "DishesTypeID": "-8989",
                    "DishesTypeName": "全部",
                }

                //database.push(a)
                database.splice(0, 0, a); // 将全部的选项放在最前
                $('#DishesType').combobox({
                    valueField: 'DishesTypeID',
                    textField: 'DishesTypeName',
                    value: '-8989',
                    text: '全部',
                    data: database
                });
            })
        }

        //添加上架信息对话框
        function AddDialog() {
            filePath = "";
            $('#editDialog').dialog('open').dialog('setTitle', '新增上架信息');
            ClearText();
            //alert(1);
            DishesTable();//传Json数据
            document.getElementById("ok").style.display = "block";
            SheID = "";
        }

        //修改上架信息对话框
        function UpdateDialog() {
            filePath = "";
            var UpdateInfoID = $("#View").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#editDialog").dialog("open").dialog("setTitle", "修改上架信息");
                BingUpdate();
                $('input,select,textarea', $('form[id="detailcontroller"]')).prop('readonly', false);
                document.getElementById("ok").style.display = "block";
            }
            else {
                $.messager.alert("友情提示", "每次只能修改一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
            }
        }

        //删除上架信息对话框
        function DeleteDialog() {
            //首先获取选中的上架信息的所有信息
            var checkdata = $("#View").datagrid("getSelections");//获取整行数据
            if (checkdata.length == 1) {
                var checkdata = $("#View").datagrid("getSelections")[0];//获取整行数据
                var postdata = {
                    SheID: checkdata.SheID,//上架ID
                    MerID: Mer,//商户ID
                    SheName: checkdata.SheName,//描述
                    SheDateB: checkdata.SheDateB,//上架日期
                    SheDateE: checkdata.SheDateE,//下架日期
                    SheTimeB: checkdata.SheTimeB,//每天允许开始时间
                    SheTimeE: checkdata.SheTimeE,//每天允许结束时间
                    MaDay: checkdata.MaDay,//允许预约天数
                    MaTime: checkdata.MaTime,//允许预约时间范围
                    SheDataGrid: "",//商品上架信息JSON
                };
                //发送异步请求删除数据
                $.messager.confirm("删除信息", "您确认删除<font color='Red' size='3'>" + "</font>该条上架信息吗？", function (ok) {
                    if (ok) {
                        $.post("/Order_Shelves/UpdateOrder_Dishes?Tag=" + 3, postdata, function (data) {
                            if (data == "1") {
                                $.messager.alert("友情提示", "删除成功");
                                initTable(Mer);
                            }
                            else {
                                $.messager.alert("友情提示", "删除失败:" + data);
                            }
                        });

                    }
                });

            }
            else {
                $.messager.alert("友情提示", "每次只能删除一行数据，你已经选择了<font color='red' size='6'>" + checkdata.length + "</font>行");
            }
        }

        //上架信息明细对话话框
        function DetailDialog() {
            var UpdateInfoID = $("#View").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#detail").dialog("open").dialog("setTitle", "上架信息");
                Bingdetail();
                document.getElementById("ok").style.display = "none";
                $('input,select,textarea', $('form[id="detailcontroller"]')).prop('readonly', true);
                //$(".textbox-text").attr('readonly', true);
            }
            else {
                $.messager.alert("友情提示", "每次只能查看一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
            }
        }
        //绑定明细
        function Bingdetail() {
            //首先获取选中的上架信息
            var checkdata = $("#View").datagrid("getSelections")[0];
            if (checkdata != null) {
                $("#d_SheID").textbox('setValue', checkdata.SheID);
                $("#d_SheDateB").datebox('setValue', checkdata.Str_SheDateB);
                $("#d_SheDateE").datebox('setValue', checkdata.Str_SheDateE);
                $("#d_SheTimeB").timespinner('setValue', checkdata.SheTimeB);
                $("#d_SheTimeE").timespinner('setValue', checkdata.SheTimeE);
                $("#d_MaDay").numberbox('setValue', checkdata.MaDay);
                var MaTime = checkdata.MaTime;
                if (MaTime != null) {
                    if (MaTime == "不允许预约") {
                        $("#d_MaTimeB").combobox('setValue', "0");
                        $("#d_MaTimeE").combobox('setValue', "0");
                    }
                    else {
                        var strs = new Array();
                        strs = MaTime.split('|');
                        $("#d_MaTimeB").combobox('setValue', strs[0]);
                        $("#d_MaTimeE").combobox('setValue', strs[1]);
                    }
                }
                $("#d_SheName").textbox('setValue', checkdata.SheName)
                $("#d_BZ").textbox('setValue', checkdata.BZ)
                SheID = checkdata.SheID;
                DishesTabledetail();//传Json数据
            }
        }

        //获取修改上架信息
        function BingUpdate() {
            //首先获取选中的上架信息
            var checkdata = $("#View").datagrid("getSelections")[0];
            if (checkdata != null) {
                $("#SheID").textbox('setValue', checkdata.SheID)
                $("#SheDateB").datebox('setValue', checkdata.Str_SheDateB)
                $("#SheDateE").datebox('setValue', checkdata.Str_SheDateE)
                $("#SheTimeB").timespinner('setValue', checkdata.SheTimeB);
                $("#SheTimeE").timespinner('setValue', checkdata.SheTimeE);
                $("#MaDay").numberbox('setValue', checkdata.MaDay);
                var MaTime = checkdata.MaTime;
                if (MaTime != null) {
                    if (MaTime == "不允许预约") {
                        $("#MaTimeB").combobox('setValue', "0")
                        $("#MaTimeE").combobox('setValue', "0")
                    }
                    else {
                        var strs = new Array();
                        strs = MaTime.split('|');
                        $("#MaTimeB").combobox('setValue', strs[0])
                        $("#MaTimeE").combobox('setValue', strs[1])
                    }
                }
                $("#SheName").textbox('setValue', checkdata.SheName)
                $("#BZ").textbox('setValue', checkdata.BZ)
                SheID = checkdata.SheID;
                DishesTable();//传Json数据
            }
        }

        //清空上架信息
        function ClearText() {

            $("#SheID").textbox('setValue', "");
            $("#SheDateB").datebox('setValue', "");
            $("#SheDateE").datebox('setValue', "");
            $("#SheTimeB").timespinner('setValue', "");
            $("#SheTimeE").timespinner('setValue', "");
            $("#MaDay").numberbox('setValue', "");
            $("#MaTimeB").combobox('setValue', "0");
            $("#MaTimeE").combobox('setValue', "0");
            $("#SheName").textbox("setValue", "");
            $("#BZ").textbox('setValue', "");
            //document.getElementById("#tb1").style.display = "block";
        }

        //保存
        function submitForm() {
            var SheDataGrid = $('#tt').datagrid('getData');
            var SheDateB = $("#SheDateB").datebox('getValue');//获取上架日期
            var MaTime;
            //alert(1);
            var MaTimeB = $("#MaTimeB").combobox('getValue');//允许预约开始时间
            var MaTimeE = $("#MaTimeE").combobox('getValue');//允许预约结束时间
            var MaDay = $("#MaDay").val();
            //alert(MaDay);
            if (MaTimeB == "0" || MaTimeE == "0" || MaDay == "") {
                MaDay = 0;
            }
            if (MaTimeB == "0" || MaTimeE == "0") {
                MaTimeB == "0";
                MaTimeE == "0";
            }
            MaTime = MaTimeB + "|" + MaTimeE;//允许预约时间拼接
            //alert("MaTime:" + MaTime);
            var postdata = {
                SheID: $("#SheID").textbox('getValue'),//上架ID
                MerID: Mer,//商户ID
                SheName: $('#SheName').textbox('getValue'),//描述
                SheDateB: $("#SheDateB").datebox('getValue'),//上架日期
                SheDateE: $("#SheDateE").datebox('getValue'),//下架日期
                SheTimeB: $("#SheTimeB").timespinner('getValue'),//每天允许开始时间
                SheTimeE: $("#SheTimeE").timespinner('getValue'),//每天允许结束时间
                MaDay: MaDay,//允许预约天数
                BZ: $("#BZ").textbox('getValue'),//备注
                MaTime: MaTime,//允许预约时间范围
                SheDataGrid: JSON.stringify(SheDataGrid.rows),//商品上架信息JSON
            };
            //首先判断前台的验证是否通过
            if (postdata.MerID != "" & postdata.SheDateB != "" & postdata.SheDateE != "" & postdata.SheTimeB != "" & postdata.SheTimeE != "") {
                //alert(1)
                var Tag = 1;//新增
                //如果上架ID不为空
                if (postdata.SheID != "") {
                    Tag = 2;//修改
                }
                //使用异步实现修改用户信息
                $.post("/Order_Shelves/UpdateOrder_Dishes?Tag=" + Tag, postdata, function (date) {
                    if (date == "1") {
                        $("#editDialog").dialog('close');
                        $("#View").datagrid('reload');
                    }
                    else {
                        $.messager.alert("友情提示", "修改失败，请检查");
                    }
                });
            }
            else {
                $.messager.alert("友情提示", "请填写上架下架日期、运营时间");
            }
        }

        //更新
        function updateActions(index) {
            $('#tt').datagrid('updateRow', {
                index: index,
                row: {}
            });
        }
        //获取当前编辑的行
        function getRowIndex(target) {
            var tr = $(target).closest('tr.datagrid-row');
            return parseInt(tr.attr('datagrid-row-index'));
        }
        //编辑行
        function editrow(target) {
            $('#tt').datagrid('beginEdit', getRowIndex(target));
        }

        //保存行编辑信息
        function saverow(target) {
            $('#tt').datagrid('endEdit', getRowIndex(target));
        }
        //取消行编辑
        function cancelrow(target) {
            $('#tt').datagrid('cancelEdit', getRowIndex(target));
        }

        //进行编辑datagrid时设置
        $.extend($.fn.datagrid.defaults.editors, {
            numberspinner: {
                init: function (container, options) {
                    var input = $('<input type="text">').appendTo(container);
                    return input.numberspinner(options);
                },
                destroy: function (target) {
                    $(target).numberspinner('destroy');
                },
                getValue: function (target) {
                    return $(target).numberspinner('getValue');
                },
                setValue: function (target, value) {
                    $(target).numberspinner('setValue', value);
                },
                resize: function (target, width) {
                    $(target).numberspinner('resize', width);
                }
            }
        });

        //商品检索
        function Search() {
            var DishesType = $('#DishesType').combobox("getValue");
            var IsShelves = $('#IsShelves').combobox("getValue");
            if (SheID == "")
            { SheID = "0" }
            if (DishesType == "-8989" || DishesType == "")
            { DishesType = "0" }
            $('#tt').datagrid({
                url: '/Order_Shelves/searchShelves?MerID=' + Mer + "&SheID=" + SheID + "&IsShelves=" + IsShelves + "&DishesType=" + DishesType,
            });
        }

        //上架信息datagrid
        function initTable(item) {
            $('#View').datagrid({
                iconCls: 'icon-user',
                loadMsg: '数据加载中...',
                fitColumns: true,
                nowrap: true,
                autoRowHeight: true,
                striped: true,
                url: '/Order_Shelves/getgrid?MerID=' + item,
                singleSelect: true,
                sortName: 'SheID',
                sortOrder: 'asc',
                border: true,
                remoteSort: false,
                idField: 'SheID',
                pageSize: 10,
                pagination: true,
                rownumbers: true,
                columns: [[
					{ field: 'SheID', title: '编号', sortable: true },
					{ field: 'Str_SheDateB', title: '上架日期', sortable: true },
                    { field: 'Str_SheDateE', title: '下架日期', sortable: true },
                    { field: 'SheTimeB', title: '运营时间' },
                    { field: 'SheTimeE', title: '停业时间' },
                    { field: 'MaDay', title: '预约天数' },
                    { field: 'MaTime', title: '预约时间范围' },
                    { field: 'SheName', title: '描述' },
                    { field: 'BZ', title: '备注' },
                ]],
                toolbar: '#tb'
            });
        }

        //商品上架数量datagrid 
        function DishesTable() {
            $('#tt').datagrid({
                loadMsg: '数据加载中...',
                fitColumns: false,
                nowrap: true,
                autoRowHeight: true,
                striped: true,
                url: '/Order_Shelves/GetShelves?MerID=' + Mer + "&SheID=" + SheID,
                sortName: 'DishesID',
                sortOrder: 'asc',
                singleSelect: true,
                border: true,
                remoteSort: false,
                idField: 'DishesID',
                pageSize: 100,
                pagination: true,
                pageList: [100],
                rownumbers: true,
                toolbar: '#tb1',
                onBeforeEdit: function (index, row) {
                    row.editing = true;
                    updateActions(index);
                },
                onAfterEdit: function (index, row) {
                    row.editing = false;
                    updateActions(index);
                },
                onCancelEdit: function (index, row) {
                    row.editing = false;
                    updateActions(index);
                }
            });
        }

        //商品上架数量datagrid 
        function DishesTabledetail() {
            $('#dd').datagrid({
                loadMsg: '数据加载中...',
                fitColumns: false,
                nowrap: true,
                autoRowHeight: true,
                striped: true,
                url: '/Order_Shelves/GetShelves?MerID=' + Mer + "&SheID=" + SheID,
                sortName: 'DishesID',
                sortOrder: 'asc',
                singleSelect: true,
                border: true,
                remoteSort: false,
                idField: 'DishesID',
                pageSize: 100,
                pagination: true,
                pageList: [100],
                rownumbers: true,
            });
        }
    </script>


    <script type="text/javascript">  //上架商品编辑
        function formatAction(value, row, index) {
            if (row.editing) {
                var s = '<a href="#" onclick="saverow(this)">保存</a> ';
                var c = '<a href="#" onclick="cancelrow(this)">取消</a>';
                return s + c;
            } else {
                var e = '<a href="#" onclick="editrow(this)">编辑</a> ';
                return e;
            }
        }
    </script>
</head>
<body style="padding: 0;">
    <div style="padding: 5px; background-color: #F4F4F4">
        <div>
            <a>商户：</a>
            <input id="SearchMer" class="easyui-combogrid" style="width: 120px" />
        </div>
    </div>
    <div>
        <table id="View"></table>
    </div>
    <div id="tb" style="padding: 5px; height: auto; background-color: #F4F4F4">
        <div style="margin-bottom: 5px">
            <a href="#" class="easyui-linkbutton" id="btndetail" iconcls="icon-more" onclick="DetailDialog()" plain="true">明细</a>
            <a href="#" class="easyui-linkbutton" id="btnadd" iconcls="icon-add" onclick="AddDialog()" plain="true">新增</a>
            <a href="#" class="easyui-linkbutton" id="btnedit" iconcls="icon-edit" onclick="UpdateDialog()" plain="true">编辑</a>
            <a href="#" class="easyui-linkbutton" id="btndell" iconcls="icon-cancel" onclick="DeleteDialog()" plain="true">删除</a>

        </div>
    </div>

    <div id="tb1" style="padding: 5px; height: auto; display: none">
        <div>
            <a>商品分类：</a>
            <input id="DishesType" class="easyui-combobox" style="width: 120px">
            <a></a>
            <a></a>
            <a></a>
            <a>已上架：</a>
            <select id="IsShelves" class="easyui-combobox" style="width: 120px">
                <option id="1" value="1">已上架</option>
                <option id="2" value="2">未上架</option>
                 <option id="3" value="3">全部</option>
            </select>
            <a href="#" class="easyui-linkbutton" iconcls="icon-search" onclick="Search()" plain="true">检索</a>
        </div>
    </div>
    @* 修改 *@
    <div id="editDialog" class="easyui-dialog" style="width: 1000px; padding: 10px" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="editController" method="post" novalidate="novalidate">
            <table cellpadding="5" width="900" id="tbledit">
                <tr hidden="hidden">
                    <td>
                        <input class="easyui-textbox" type="text" id="SheID" name="SheID" />
                    </td>
                </tr>
                <tr>
                    <td width="85" class="userinfo-td-l">上架日期：</td>
                    <td width="100" class="userinfo-td-r">
                        <input class="easyui-datebox" type="text" id="SheDateB" name="SheDateB" />
                    </td>
                    <td width="-8"></td>
                    <td width="85" class="userinfo-td-l">下架日期：</td>
                    <td width="100" class="userinfo-td-r">
                        <input class="easyui-datebox" type="text" id="SheDateE" name="SheDateE" />
                    <td width="-8"></td>
                    <td width="75" class="userinfo-td-l">允许下单时间：</td>
                    <td width="100" class="userinfo-td-r">
                        <input class="easyui-timespinner" id="SheTimeB" name="SheTimeB" /></td>
                    <td width="-8" class="userinfo-td-l">至</td>
                    <td width="61" class="userinfo-td-r">
                        <input class="easyui-timespinner" id="SheTimeE" name="SheTimeE" /></td>
                </tr>
                <tr></tr>
                <tr>
                    <td class="userinfo-td-l">允许预约天数：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-numberbox" type="text" id="MaDay" name="MaDay" /></td>
                    <td width="-8"></td>
                    <td width="85" class="userinfo-td-l">允许预约时间：</td>
                    <td width="100" class="userinfo-td-r">
                        <select id="MaTimeB" class="easyui-combobox" style="width: 140px;">
                        </select>
                    <td width="8" class="userinfo-td-l">至</td>
                    <td width="61" class="userinfo-td-r">
                        <select class="easyui-combobox" id="MaTimeE" style="width: 140px;" /></td>
                </tr>
                <tr></tr>
                <tr>
                    <td class="userinfo-td-l">描述：</td>
                    <td class="userinfo-td-r" colspan="9">
                        <textarea class="easyui-textbox"style="width: 800px; " rows="5" id="SheName" name="SheName" ></textarea>
                    </td>
                </tr>
                <tr></tr>
                <tr>
                    <td class="userinfo-td-l">备注：</td>
                    <td class="userinfo-td-r" colspan="9">
                        <input class="easyui-textbox" data-options="multiline:true" style="width: 800px; height: 50px" id="BZ" name="BZ"/>
                    </td>
                </tr>
                <tr></tr>
            </table>
            <br />
            <div align="center">
                <table id="tt" style="width: 600px; height: 250px;" title="上架商品管理" iconcls="icon-edit">
                    <thead>
                        <tr>
                            <th field="DishesID" width="60" align="center">商品ID</th>
                            <th field="DishesTypeName" width="150" align="center">商品分类</th>
                            <th field="DishesNmae" width="150" align="center">商品名称</th>
                            <th field="DishesNub" width="107" align="center" editor="numberspinner">上架数量</th>
                            <th field="action" width="100" align="center" formatter="formatAction">编辑</th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
            <br />
            <div id="ok" align="center" style="display: block">
                <a href="javascript:void(0)" id="submit" class="easyui-linkbutton" iconcls="icon-ok" onclick="submitForm()">保存</a>
            </div>
        </form>
    </div>

    @* 明细 *@
    <div id="detail" class="easyui-dialog" style="width: 1000px; padding: 10px" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="detailcontroller" method="post" novalidate="novalidate">
            <table cellpadding="5" width="900" id="tbldetail">
                <tr hidden="hidden">
                    <td>
                        <input class="easyui-textbox" type="text" id="d_SheID" name="SheID" />
                    </td>
                </tr>
                <tr>
                    <td width="85" class="userinfo-td-l">上架日期：</td>
                    <td width="100" class="userinfo-td-r">
                        <input class="easyui-datebox" type="text" id="d_SheDateB" name="d_SheDateB" />
                    </td>
                    <td width="-8"></td>
                    <td width="85" class="userinfo-td-l">下架日期：</td>
                    <td width="100" class="userinfo-td-r">
                        <input class="easyui-datebox" type="text" id="d_SheDateE" name="d_SheDateE" />
                    <td width="-8"></td>
                    <td width="75" class="userinfo-td-l">允许下单时间：</td>
                    <td width="100" class="userinfo-td-r">
                        <input class="easyui-timespinner" id="d_SheTimeB" name="d_SheTimeB" /></td>
                    <td width="-8" class="userinfo-td-l">至</td>
                    <td width="61" class="userinfo-td-r">
                        <input class="easyui-timespinner" id="d_SheTimeE" name="d_SheTimeE" /></td>
                </tr>
                <tr></tr>
                <tr>
                    <td class="userinfo-td-l">允许预约天数：</td>
                    <td class="userinfo-td-r">
                        <input class="easyui-numberbox" type="text" id="d_MaDay" name="d_MaDay" /></td>
                    <td width="-8"></td>
                    <td width="85" class="userinfo-td-l">允许预约时间：</td>
                    <td width="100" class="userinfo-td-r">
                        <select id="d_MaTimeB" class="easyui-combobox" style="width: 140px;">
                        </select>
                    <td width="8" class="userinfo-td-l">至</td>
                    <td width="61" class="userinfo-td-r">
                        <select class="easyui-combobox" id="d_MaTimeE" style="width: 140px;" /></td>
                </tr>
                <tr></tr>
                <tr>
                    <td class="userinfo-td-l">描述：</td>
                    <td class="userinfo-td-r" colspan="9">
                        <intput class="easyui-textbox"style="width: 800px; " rows="5" id="d_SheName" name="SheName" />
                    </td>
                </tr>
                <tr></tr>
                <tr>
                    <td class="userinfo-td-l">备注：</td>
                    <td class="userinfo-td-r" colspan="9">
                        <input class="easyui-textbox" data-options="multiline:true" style="width: 800px; height: 50px" id="d_BZ" name="BZ"/>
                    </td>
                </tr>
                <tr></tr>
            </table>
            <br />
            <div align="center">
                <table id="dd" style="width: 500px; height: 250px;" title="上架商品管理" iconcls="icon-edit">
                    <thead>
                        <tr>
                            <th field="DishesID" width="60" align="center">商品ID</th>
                            <th field="DishesTypeName" width="150" align="center">商品分类</th>
                            <th field="DishesNmae" width="150" align="center">商品名称</th>
                            <th field="DishesNub" width="110" align="center" editor="numberspinner">上架数量</th>
                        </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
            <br />
        </form>
    </div>

</body>
</html>
